package com.caixy.adminSystem.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caixy.adminSystem.common.ErrorCode;
import com.caixy.adminSystem.exception.BusinessException;
import com.caixy.adminSystem.exception.ThrowUtils;
import com.caixy.adminSystem.model.entity.FileCategory;
import com.caixy.adminSystem.service.FileCategoryService;
import com.caixy.adminSystem.service.FileService;
import com.caixy.adminSystem.mapper.FileCategoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author dio
* @description 针对表【tb_file_category(文件分类信息)】的数据库操作Service实现
* @createDate 2024-06-23 19:03:16
*/
@Service
public class FileCategoryServiceImpl extends ServiceImpl<FileCategoryMapper, FileCategory>
    implements FileCategoryService {


    @Override
    public void check(FileCategory fileCategory, Boolean add) {
        if (fileCategory==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

//        无参
        if (add){
           ThrowUtils.throwIf(StringUtils.isAnyBlank(fileCategory.getDescription(),fileCategory.getName()),ErrorCode.PARAMS_ERROR);

        }
//        有参
        if (StringUtils.isNotBlank(fileCategory.getDescription())&&fileCategory.getDescription().length()>8192){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"描述过长");
        }
        if (StringUtils.isNotBlank(fileCategory.getName())&&fileCategory.getName().length()>80){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"名字过长");
        }
    }
}




